package client;

/* Instance Generator
 * ---------------------------------------------------
 * Written by
 * Rebecca Van Bussel 6271316
 * October 6, 2013
 */

import java.util.Random;


public class InstanceGenerator {

	private Random rng = new Random();

	private final String[] DIRECTIONS = {"North", "East", "South", "West"};
	private final String[] PROVINCES = {"AB", "BC", "MB", "NB", "NL", "NS", "NT", "NU", "ON", "PE", "QC", "SK", "YT"};
	private final String[] MONTHS = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
	private final String[] M_STATUS = {"Missing", "Found"};
	private final String[] C_STATUS = {"Captured", "At large"};

	private String fname;
	private String lname;
	private String address;
	private String date;
	private String location;
	private String status;


	public InstanceGenerator(char type) {

		//generate record values
		fname = generateString(rng.nextInt(6)+3);
		lname = generateString(rng.nextInt(6)+3);
		String addressNum = Integer.toString(rng.nextInt(9999)+1);
		String streetName = generateString(rng.nextInt(12)+3);
		String direction = DIRECTIONS[rng.nextInt(DIRECTIONS.length)];
		String city = generateString(rng.nextInt(12)+3);
		String province = PROVINCES[rng.nextInt(PROVINCES.length)];
		String postalCode = Character.toString((char)(65+rng.nextInt(26)))+rng.nextInt(10)+
				(char)(65+rng.nextInt(26))+" "+rng.nextInt(10)+(char)(65+rng.nextInt(26))+
				rng.nextInt(10);				
		address = addressNum+" "+streetName+" "+direction+", "+city+", "+province+", "+postalCode;

		String month = MONTHS[rng.nextInt(MONTHS.length)];
		int day = rng.nextInt(31)+1;
		int year = rng.nextInt(34)+1980;				
		date = month+" "+day+", "+year;

		String addressNum2 = Integer.toString(rng.nextInt(9999)+1);
		String streetName2 = generateString(rng.nextInt(12)+3);
		String direction2 = DIRECTIONS[rng.nextInt(DIRECTIONS.length)];
		String city2 = generateString(rng.nextInt(12)+3);
		String province2 = PROVINCES[rng.nextInt(PROVINCES.length)];
		String postalCode2 = Character.toString((char)(65+rng.nextInt(26)))+rng.nextInt(10)+
				(char)(65+rng.nextInt(26))+" "+rng.nextInt(10)+(char)(65+rng.nextInt(26))+
				rng.nextInt(10);				
		location = addressNum2+" "+streetName2+" "+direction2+", "+city2+", "+province2+", "+postalCode2;
		if (type=='M')
			status = M_STATUS[rng.nextInt(M_STATUS.length)];
		else
			status = C_STATUS[rng.nextInt(C_STATUS.length)];
	}

	public String getFname() {
		return fname;
	}

	public void setFname(String fname) {
		this.fname = fname;
	}

	public String getLname() {
		return lname;
	}

	public void setLname(String lname) {
		this.lname = lname;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	private String generateString(int length) {
		char[] text = new char[length];
		String vowels = "aeiou";
		for (int i = 0; i < length; i++)
		{
			text[i] = (char)(97+rng.nextInt(26));
			//adding some vowels in to make the words a little more interesting...
			if (++i<length)
				text[i] = vowels.charAt(rng.nextInt(vowels.length()));
		}
		text[0] = Character.toUpperCase(text[0]);
		return new String(text);
	}

}
